package hw;

import sk.Util;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MenuPanel extends JPanel implements ActionListener {
    private ATM atm;
    private JButton saveBtn;
    private JButton getBtn;
    private JButton lookBtn;
    private Icon saveImg = Util.getImageIcon("/images/buttonSave.jpg");
    private Icon getImg = Util.getImageIcon("/images/buttonGet.jpg");
    private Icon lookImg = Util.getImageIcon("/images/buttonFind.jpg");

    public MenuPanel(ATM atm) {
        this.atm = atm;
        this.setLayout(null);
        this.setOpaque(false);

        saveBtn = new JButton(saveImg);
        saveBtn.setBounds(10, 100, 140, 50);
        this.add(saveBtn);
        saveBtn.addActionListener(this);

        getBtn = new JButton(getImg);
        getBtn.setBounds(10, 170, 140, 50);
        this.add(getBtn);
        getBtn.addActionListener(this);

        lookBtn = new JButton(lookImg);
        lookBtn.setBounds(10, 240, 140, 50);
        this.add(lookBtn);
        lookBtn.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == saveBtn) {
            atm.switchPanel("save");
        } else if (e.getSource() == getBtn) {
            atm.switchPanel("get");
        } else if (e.getSource() == lookBtn) {
            atm.switchPanel("look");
        }
    }
}
